package com.ejd.utils;

import com.ejd.web.bo.impl.NCounter;

public class NCounterUtil {
    public static final String ZERO_STRING = "0";
    public static String getNo(NCounter nCounter){
        String prefix = (null == nCounter.getPrefix())?"":nCounter.getPrefix();
        Integer nextNumber = nCounter.getCounterNext();
        Integer counterLength = nCounter.getCounterLength();
        String counter = constructLastCounter(counterLength, nextNumber);
        return prefix + counter;
    }

    public static String constructLastCounter(Integer counterLength, Integer lastCounter){
        String str = String.valueOf(lastCounter);
        StringBuffer buffer = new StringBuffer();
        for(int i=0; i<counterLength-str.length(); i++){
            buffer.append(ZERO_STRING);
        }
        buffer.append(str);
        return buffer.toString();
    }


}
